/**
 * FieldMetaData.java	1.0 2007 六月 6 11:40:10,创建
 */

package org.in4j.search.index.sandbox;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;

/**
 *
 * @author 杨帆
 * @version 1.0 2007 六月 6 11:40:10,创建
 */
public class FieldMetaData
{
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(FieldMetaData.class);

	private Store store;
	private Index index;

	/**
	 * 存储方式
	 * @see org.apache.lucene.document.Field.Store
	 */
	private enum StoreStrategy
	{
		/**
		 * 保存原始的字段值.用于短文本,比如文档标题之类需要显示的结果
		 */
		YES("YES"),
		/**
		 * 不存储此字段的值到到索引文件
		 */
		NO("NO"),
		/**
		 * 把索引压缩后进行保存,用于长文档和二进制字段
		 */
		COMPRESS("COMPRESS");
		StoreStrategy(String value){};
	}

	/**
	 * 索引方式
	 * @see org.apache.lucene.document.Field.Index
	 */
	private enum IndexStrategy
	{
		NO("NO"),
		TOKENIZED("TOKENIZED"),
		UN_TOKENIZED("UN_TOKENIZED"),
		NO_NORMS("NO_NORMS");
		IndexStrategy(String value){};
	}

	public FieldConverter getFieldConverter()
	{
		// TODO 自动生成方法存根
		if(true)
			throw new UnsupportedOperationException();
		return null;
	}

	public boolean isDate()
	{
		// TODO 自动生成方法存根
		if(true)
			throw new UnsupportedOperationException();
		return false;
	}

	public String getSourceName()
	{
		// TODO 自动生成方法存根
		if(true)
			throw new UnsupportedOperationException();
		return null;
	}

	public String getFieldName()
	{
		// TODO 自动生成方法存根
		if(true)
			throw new UnsupportedOperationException();
		return null;
	}

	public Field createField(String value)
	{
		Field field = new Field(this.getFieldName(),value,getStore(),getIndex());
		return field;
	}

	public Store getStore()
	{
		return this.store;
	}

	public Index getIndex()
	{
		return this.index;
	}

	public void setStoreStrategy(String strategy)
	{
		StoreStrategy storeStrategy = StoreStrategy.valueOf(strategy.toUpperCase());
		if(storeStrategy == StoreStrategy.YES)
			this.store = Field.Store.YES;
		if(storeStrategy == StoreStrategy.NO)
			this.store = Field.Store.NO;
		if(storeStrategy == StoreStrategy.COMPRESS)
			this.store = Field.Store.COMPRESS;
		throw new IllegalStateException("Store类型设置不正确.");
	}

	public void setIndexStrategy(String strategy)
	{
		IndexStrategy indexStrategy = IndexStrategy.valueOf(strategy.toUpperCase());
		if(indexStrategy == IndexStrategy.NO)
			this.index = Field.Index.NO;
		if(indexStrategy == IndexStrategy.NO_NORMS)
			this.index = Field.Index.NO_NORMS;
		if(indexStrategy == IndexStrategy.TOKENIZED)
			this.index = Field.Index.TOKENIZED;
		if(indexStrategy == IndexStrategy.UN_TOKENIZED)
			this.index = Field.Index.UN_TOKENIZED;
		throw new IllegalStateException("Index类型设置不正确:" + strategy);
	}
}
